package cn.iocoder.yudao.module.system.dal.mysql.tradinghours;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.tradinghours.vo.SystemTradingHoursPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.tradinghours.SystemTradingHoursDO;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDate;
import java.util.List;

/**
 * 营业时间 Mapper
 *
 * @author admin
 */
@Mapper
public interface SystemTradingHoursMapper extends BaseMapperX<SystemTradingHoursDO> {

    default PageResult<SystemTradingHoursDO> selectPage(SystemTradingHoursPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<SystemTradingHoursDO>()
                .eqIfPresent(SystemTradingHoursDO::getType, reqVO.getType())
                .eqIfPresent(SystemTradingHoursDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(SystemTradingHoursDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(SystemTradingHoursDO::getId));
    }

    /**
     * 根据类型和星期几查询营业时间
     *
     * @param type 类型
     * @param dayOfWeek 星期几
     * @return 营业时间
     */
    default SystemTradingHoursDO selectByTypeAndDayOfWeek(Integer type, Integer module, Integer dayOfWeek) {
        return selectOne(new LambdaQueryWrapperX<SystemTradingHoursDO>()
                .eq(SystemTradingHoursDO::getType, type)
                .eq(SystemTradingHoursDO::getModule, module)
                .eq(SystemTradingHoursDO::getDayOfWeek, dayOfWeek));
    }

    /**
     * 根据类型和特殊交易日期查询营业时间
     *
     * @param type 类型
     * @param tradingDate 特殊交易日期
     * @return 营业时间
     */
    default SystemTradingHoursDO selectByTypeAndTradingDate(Integer type, Integer module, LocalDate tradingDate) {
        return selectOne(new LambdaQueryWrapperX<SystemTradingHoursDO>()
                .eq(SystemTradingHoursDO::getType, type)
                .eq(SystemTradingHoursDO::getModule, module)
                .eq(SystemTradingHoursDO::getTradingDate, tradingDate));
    }

    /**
     * 根据类型查询营业时间列表
     *
     * @param type 类型
     * @return 营业时间列表
     */
    default List<SystemTradingHoursDO> selectListByType(Integer type, Integer module) {
        return selectList(new LambdaQueryWrapperX<SystemTradingHoursDO>()
                .eq(SystemTradingHoursDO::getType, type)
                .eq(SystemTradingHoursDO::getModule, module)
        );
    }

    /**
     * 根据类型和日期范围查询营业时间列表
     *
     * @param type 类型
     * @param startDate 开始日期
     * @param endDate 结束日期
     * @return 营业时间列表
     */
    default List<SystemTradingHoursDO> selectListByTypeAndDateRange(Integer type, Integer module, LocalDate startDate, LocalDate endDate) {
        return selectList(new LambdaQueryWrapperX<SystemTradingHoursDO>()
                .eq(SystemTradingHoursDO::getType, type)
                .eq(SystemTradingHoursDO::getModule, module)
                .betweenIfPresent(SystemTradingHoursDO::getTradingDate, startDate, endDate)
                .orderByAsc(SystemTradingHoursDO::getTradingDate));
    }

}